package com.xzakota.minesweeper.ui.dialog;

import com.xzakota.minesweeper.R;
import com.xzakota.minesweeper.controller.GameResource;
import com.xzakota.minesweeper.ui.dialog.templae.AbstractBaseDialog;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

/**
 * 帮助对话框
 *
 * @author Xzakota
 */
public class HelpDialog extends AbstractBaseDialog {
    public HelpDialog(Window parent) {
        setTitle("扫雷英雄榜");

        setResizable(true);
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        initLayout();

        Rectangle bounds = parent.getBounds();
        bounds.x += bounds.width;
        bounds.width = 400;
        bounds.height = 400;
        setBounds(bounds);
    }

    private void initLayout() {
        JEditorPane editorPane;
        try {
            editorPane = new JEditorPane(GameResource.getHTMLResource(R.HTML.HTML_HELP));
        } catch (IOException e) {
            editorPane = new JEditorPane("text/html", "<center><h1>无法加载帮助文件,请检查配置</h1></center>");
        }
        editorPane.setContentType("text/html;charset=utf-8");
        editorPane.setEditable(false);
        JScrollPane jScrollPane = new JScrollPane(editorPane);
        add(jScrollPane);
    }
}
